package com.neutech.maplestory.entity;

import com.neutech.maplestory.client.MapleStoryClient;
import com.neutech.maplestory.util.ImageUtil;

import java.awt.*;

public class Power extends AbstractMapleStoryObject{
        public static Image[] imgs = new Image[10];
        static {
            for (int i = 0; i < 10; i++) {
                imgs[i] = ImageUtil.getImage("power"+ i);
            }
        }
        public Power (){
            this.speed = 5;
            this.live = true;
        }

        /**
         * 每一个伤害值
         */
        public int value;
        public Power (MapleStoryClient msc, int x, int y){
            this();
            this.msc = msc;
            this.x = x;
            this.y = y;
            this.value = msc.hero.hitValue;

        }
        @Override
        public void draw(Graphics g) {
            if (!live){
                msc.powers.remove(this);
                return;
            }
            drawValue(g);
//        g.drawString(value + "",x,y);
            move();
        }

        /**
         * 使用图片画伤害值
         * @param g  画笔
         */
        public void drawValue(Graphics g){
            int power = this.value;
//            g.drawImage(imgs[3], x, y, null);
            if (power >= 9999){
                power = 9999;
            }
            int units = power % 10;
            power = power / 10;
            int tens = power % 10;
            power = power / 10;
            int hunders = power % 10;
            power = power / 10;
            int thousands = power;
            if (tens == 0 && hunders ==0 && thousands ==0 && units !=0){
                //画个位
                g.drawImage(imgs[units],x,y,null );
            }
            if (hunders ==0 && thousands ==0 && tens != 0){
                //画十位
                g.drawImage(imgs[tens],x,y,null );
                //画个位
                g.drawImage(imgs[units],x+30,y,null );
            }
            if (hunders !=0 && thousands ==0 ){
                //画百位
                g.drawImage(imgs[hunders],x,y,null );
                //画十位
                g.drawImage(imgs[tens],x+30,y,null );
                //画个位
                g.drawImage(imgs[units],x+60,y,null );
            }
            if ( thousands !=0 ){
                //画千位
                g.drawImage(imgs[thousands],x,y,null );
                //画百位
                g.drawImage(imgs[hunders],x+30,y,null );
                //画十位
                g.drawImage(imgs[tens],x+60,y,null );
                //画个位
                g.drawImage(imgs[units],x+90,y,null );
            }

        }
        @Override
        public void move() {
            if (this.y <= 300){
                this.live = false;
            }
            this.y -= speed;
    }
}
